<?php class MNewsletter extends CI_Model {

	  function __construct()
	    {
		parent::__construct();
	    }

	function getAllNewsletter() {
		$data = array();
		$Q = $this->db->get('newsletter');
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
			$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}
	
	function selectEmailClinic($id_clinique) {
		$nom = "";
		$sql = "SELECT * FROM clinique where id_clinique = '$id_clinique'";
		//echo $sql;
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$email = $row['email'];
			}
			return $email;
		}
		$Q->free_result();
	}
	
	function selectEmailPatient($id_patient) {
		$nom = "";
		$sql = "SELECT * FROM patient where id_patient = '$id_patient'";
		//echo $sql;
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$email = $row['email'];
			}
			return $email;
		}
		$Q->free_result();
	}
	
	function getNewsletter($id) {
		$sql = "SELECT * FROM newsletter WHERE id_newsletter  = '$id'";			
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}
	
	function insertNewsletter($data) {
		return $this->db->insert('newsletter', $data);
	}	
	
	function modifIsEnvoie($id_newletter) {
		$sql1 ="UPDATE newsletter SET isEnvoi = '1' WHERE id_newsletter =$id_newletter";
		$this->db->query($sql1);
	}	
	

//
}//end class
?>